﻿using System.Text;
using System.Threading.Tasks;
using HK.Core.Common.Data;
using HK.Core.Utils;

namespace HK.Core.IO.Protocol.Output
{
    /// <summary>
    /// 文件Io模式
    /// </summary>
    public enum FileIoMode
    {
        /// <summary>
        /// 无
        /// </summary>
        None = 0x00000000,
        
        /// <summary>
        /// Json
        /// </summary>
        Json = 0x00000001,
        
        /// <summary>
        /// Csv
        /// </summary>
        Csv = 0x00000002,
        
        /// <summary>
        /// 二进制
        /// </summary>
        Binary = 0x00000004,
        
        /// <summary>
        /// 全部
        /// </summary>
        All = Binary | Json | Csv
    }
    
    /// <summary>
    /// 接口 : 文件I/O协议
    /// </summary>
    public interface IFileIO
    {
        /// <summary>
        /// I/O 模式
        /// </summary>
        FileIoMode Mode { get; }
        
        /// <summary>
        /// 路径
        /// </summary>
        string Path { get; }

        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="iOnCompleted">导入完成回调</param>
        /// <returns>true:OK; false:NG;</returns>
        bool Import(UtilsTask.TaskCompleted iOnCompleted);

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="iOnCompleted">导入完成回调</param>
        /// <returns>true:OK; false:NG;</returns>
        Task<bool> Export(UtilsTask.TaskCompleted iOnCompleted = null);

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns>true:OK; false:NG;</returns>
        bool Delete();
    }

    /// <summary>
    /// 接口 : 文件I/O协议
    /// </summary>
    /// <typeparam name="TData">数据类型</typeparam>
    public interface IFileIO<out TData> : IFileIO
        where TData : JsonData
    {
        /// <summary>
        /// 数据
        /// </summary>
        TData Data { get; }
        
        /// <summary>
        /// 字节编码
        /// <para>* 默认 : UTF-8</para>
        /// </summary>
        Encoding Encoding { get; }
    }
}
